﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace slwhTools.SLog
{
    public class LogService<T> : ISLogService<T>
    {
        private readonly ILogger<T> _logger;

        public LogService(ILogger<T> logger)
        {
            _logger = logger;
        }

        public void LogTrace(string message, params object[] args)
            => _logger.LogTrace(message, args);

        public void LogDebug(string message, params object[] args)
            => _logger.LogDebug(message, args);

        public void LogInformation(string message, params object[] args)
            => _logger.LogInformation(message, args);

        public void LogWarning(string message, params object[] args)
            => _logger.LogWarning(message, args);

        public void LogError(string message, params object[] args)
            => _logger.LogError(message, args);

        public void LogError(Exception exception, string message, params object[] args)
            => _logger.LogError(exception, message, args);

        public void LogCritical(string message, params object[] args)
            => _logger.LogCritical(message, args);

        public void LogCritical(Exception exception, string message, params object[] args)
            => _logger.LogCritical(exception, message, args);

        public void LogWithData(string message, object data)
        {
            if (data == null)
            {
                _logger.LogInformation("{Message}", message);
            }
            else
            {
                _logger.LogInformation("{Message} {@Data}", message, data);
            }
        }

        public IDisposable BeginScope<TState>(TState state)
            => _logger.BeginScope(state);
    }
}
